<!doctype html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="../../css/mui.min.css" rel="stylesheet" />

		<style type="text/css">
			.mui-input-row {
				position: absolute;
				left: 35px;
				right: 18px;
				bottom: 0px;
				z-index: 99;
			}
			
			.mui-input-row input {
				color: black;
				background-color: #EFEFF4;
			}
			
			.fiends-div {
				width: 100%;
				background-color: #FFFFFF;
				border-bottom: 1px solid #F7F7F7;
				align-items: center;
				padding: 2% 0;
				font-size: 120%;
				display: none;
			}
			
			.fiends-div2 {
				width: 100%;
				font-size: 100%;
				display: block;
				color: #A9A9A9;
				padding-top: %;
			}
			
			.text-input {
				border: 0;
			}
			
			.friend-heddimg {
				width: 12%;
				margin-right: 5%;
				margin-left: 5%
			}
			
			.text-input {
				display: none;
			}
			
			.mui-btn {
				width: 90%;
				margin-left: 5%;
				margin-top: 5%;
				display: none;
			}
			
			.mui-table-view:after,
			.mui-table-view:before {
				background-color: white!important;
			}
		</style>
	</head>

	<body>

		<header class="mui-bar mui-bar-nav" id="header">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<span class="mui-title">扫描结果</span>
		</header>
		<div class="mui-content">
			<div id="fiends-div1" class="fiends-div">
				<img src="" class="friend-heddimg" />
				<text></text>
			</div>
			<div id="fiends-div2" class="fiends-div2">
				<textarea class="text-input" id="text-input" placeholder="添加验证信息..."></textarea>
			</div>
			<button type="button" class="mui-btn mui-btn-blue" id="addbutton">添加为好友</button>
		</div>

		<script src="../../js/mui.min.js"></script>
		<script src="../../js/immersed.js"></script>
		<script type="text/javascript">
			mui.init();
			mui.plusReady(function() {
				starbar();
				plus.navigator.setStatusBarStyle('dark');

				//重写返回事件
				var old_back = mui.back;
				mui.back = function() {
					old_back();
					plus.navigator.setStatusBarStyle('light');

				}
				
				
				var a = "";
				var b = "";
				var data = plus.webview.currentWebview().data;
				var ta_Card = plus.webview.currentWebview().ta_card
				var headimg = document.getElementById('fiends-div1');
				var addbtn = document.getElementById('addbutton');
				var addtext = document.getElementById('text-input');
				if(data.user != null) {
					a = data.user.lyuser_FacePath;
					b = data.user.lyuser_NickName;
					var viewwidth = document.body.clientWidth;
					var headimg = document.getElementById('fiends-div1');;
					headimg.style.display = 'flex';
					addbtn.style.display = 'none';
					addtext.style.display = 'none';
					headimg.style.display = 'flex';
					headimg.getElementsByTagName('img')[0].src = a;
					headimg.getElementsByTagName('img')[0].style.height = "-webkit-calc(" + viewwidth * 0.12 + "px)";
					headimg.getElementsByTagName('text')[0].textContent = b;
					plus.nativeUI.closeWaiting ();
				} else if(data.userr && ta_Card != plus.storage.getItem("card")) {
					a = data.userr.lyuser_FacePath;
					b = data.userr.lyuser_NickName;
					var viewwidth = document.body.clientWidth;
					headimg.style.display = 'flex';
					addbtn.style.display = 'block';
					addtext.style.display = 'block';
					headimg.getElementsByTagName('img')[0].src = a;
					headimg.getElementsByTagName('img')[0].style.height = "-webkit-calc(" + viewwidth * 0.12 + "px)";
					headimg.getElementsByTagName('text')[0].textContent = b;
					plus.nativeUI.closeWaiting();
				} else if(data.userr && ta_Card == plus.storage.getItem("card")) {
					a = data.userr.lyuser_FacePath;
					b = data.userr.lyuser_NickName;
					var viewwidth = document.body.clientWidth;
					headimg.style.display = 'flex';
					addbtn.style.display = 'none';
					addtext.style.display = 'none';
					headimg.getElementsByTagName('img')[0].src = a;
					headimg.getElementsByTagName('img')[0].style.height = "-webkit-calc(" + viewwidth * 0.12 + "px)";
					headimg.getElementsByTagName('text')[0].textContent = b;
					plus.nativeUI.closeWaiting();
				} else {
					plus.nativeUI.closeWaiting();
					mui.toast('未找到该账号!')
				}
				//点击添加好友事件
				document.getElementById('addbutton').addEventListener('tap', function() {
					var _this = this;
					mui.confirm('确认添加此人为好友？', function(e) {
						if(e.index == 0) {
							var addtext = document.getElementById('text-input');
							mui.ajax({
								url: 'https://www.lunyuwang.com/friendListController/clickAdd',
								data: {
									lyaddrequest_Text: addtext.value,
									lyaddrequest_Card: plus.storage.getItem("card"),
									lyaddrequested_Card: card.value
								},
								async: true, //将false改为true
								crossDomain: true, //强制使用5+跨域
								dataType: 'json', //服务器返回json格式数据
								type: 'get', //HTTP请求类型
								timeout: 10000, //超时时间设置为10秒；
								//processData: false,
								headers: {
									'Content-Type': 'application/x-www-form-urlencoded'
								},
								success: function(data) {
									console.log(data.state)
									//服务器返回响应，根据响应结果，分析是否登录成功；15693321098
									if(data.state == 1) {
										mui.toast('好友申请发送成功!')
									}

								},
								error: function(xhr, type, errorThrown) {
									//异常处理；
									mui.alert("失败了！")

								}
							})
						}

					})
				})

				//跳转到该用户详情页面
				document.getElementById('fiends-div1').addEventListener('tap', function() {
					mui.openWindow({
						url: 'addzhuhtml.html',
						id: 'addzhuhtml.html',
						extras: {
							card: ta_Card
						}
					})
				})

			})
		</script>
	</body>

</html>